Skip to content

fix: ignore double colon cast operators in SQL parameter substitution - #3414

Merged
kukushking merged 1 commit into
aws:mainfrom
hsusul:fix/sql-formatter-double-colon
Jul 31, 2026
Merged

fix: ignore double colon cast operators in SQL parameter substitution#3414
kukushking merged 1 commit into
aws:mainfrom
hsusul:fix/sql-formatter-double-colon

Conversation

@hsusul

@hsusul hsusul commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an issue in awswrangler._sql_formatter._process_sql_params where double-colon type cast operators (e.g. col::text, col::timestamp, col::varchar, col::integer) are mistakenly parsed as parameter placeholders when a parameter name matches the cast target type name.

Root Cause

The parameter substitution regex _PATTERN was defined as re.compile(r":([A-Za-z0-9_]+)(?![A-Za-z0-9_])"). When a SQL query contains double colons :: (standard ANSI / PostgreSQL / Athena / Presto / Trino / CleanRooms cast syntax), the second colon was matched as a parameter placeholder. If params contained a key matching the type name (such as text in col::text), _process_sql_params substituted the cast operator, corrupting the SQL query to col:'value' and causing runtime SQL syntax errors.

Solution

Updated _PATTERN in awswrangler/_sql_formatter.py with a negative lookbehind (?<!:) to ensure single-colon parameters (e.g., :id) are matched without matching double-colon cast operators (::type):

_PATTERN = re.compile(r"(?<!:):([A-Za-z0-9_]+)(?![A-Za-z0-9_])")

Validation & Testing

  • Added unit test test_process_sql_params_double_colon_cast in tests/unit/test_sql_params_formatter.py asserting that double-colon type casts are preserved while parameter placeholders are correctly substituted.
  • Confirmed test failure on upstream/main baseline before applying fix.
  • Ran quality checks:
    • pytest tests/unit/test_sql_params_formatter.py (Passed 13/13)
    • ruff format --check . (Passed)
    • ruff check . (Passed)
    • mypy awswrangler/_sql_formatter.py tests/unit/test_sql_params_formatter.py (Success)
    • git diff --check (Clean)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kukushking

Copy link
Copy Markdown
Collaborator

Thanks @hsusul !

@kukushking
kukushking merged commit 4f7daf7 into aws:main Jul 31, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants